import book.BookList;
import user.Person;
import user.Root;
import user.User;

import java.util.Scanner;


public class Main {

    public static Person login() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入你的姓名：");
        String name = scanner.next();
        while(true) {
            System.out.print("请选择访问权限（!0->我是访客   0->我是管理员）:");
            int choice = scanner.nextInt();
            if(choice == 0) {//管理员
                System.out.print("请输入管理员密码：");
                String a = scanner.next();
                if(a.equals(Root.getRootmima())) {
                    System.out.println("管理员密码正确，登录成功！！！");
                    return new Root(name);
                }
                else {
                    System.out.println("密码错误！！！");
                }
            } else {//访客
                System.out.println("访客登录成功！！！");
                return new User(name);
            }
        }

    }

    public static void main(String[] args) {
        Person person =  login();
        BookList booklist = new BookList();
        person.huanying();
        while(true) {
            int chouse = person.menu();
            if(chouse > person.iOperation.length) {
                System.out.println("输入不合法，请选择合法的选项！！！");
                continue;
            }
            person.caouo(chouse,booklist);
        }
    }
}
